﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PatientManagement.Database;
using PatientManagement.Managers;
using PatientManagement.Common.Utils;

namespace PatientManagement
{
    public partial class FormAddPatient : Form
    {
        public int PatientId = -1;
        public FormAddPatient()
        {
            InitializeComponent();
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(tbName.Text))
            {
                errorProvider.SetError(tbName, "Vui lòng nhập tên");
                return;
            }

            var patient = new Patient()
            {
                Name = tbName.Text,
                Address = tbAddress.Text,
                Birthday = dtpBirthday.Value,
                PhoneNumber = tbPhone.Text,
                Sex = rbMale.Checked ? true : false,
                PatientId = Utilities.GenerateIdNumber(),
            };

            PatientId = ServiceManager.Instance.AddPatient(patient);
            if (PatientId == -1)
            {
                MessageBox.Show("Thêm thất bại");
            }
            this.Close();
        }
    }
}
